package com.huatai.datacenter.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huatai.datacenter.entity.dto.RequestLogStatVo;
import com.huatai.datacenter.mapper.TbFireDataRequestLogEntityMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RequestLogService {

    @Resource
    private TbFireDataRequestLogEntityMapper logMapper;

    public Page<RequestLogStatVo> getRequestLogStats(com.huatai.datacenter.entity.dto.RequestLogDto dto) {
        // 执行统计查询
        List<RequestLogStatVo> stats = logMapper.getRequestLogStats(dto);
        
        // 手动分页处理
        int page = dto.getPage() != null ? dto.getPage() : 1;
        int limit = dto.getLimit() != null ? dto.getLimit() : 10;
        int start = (page - 1) * limit;
        int end = Math.min(start + limit, stats.size());
        
        // 创建分页对象
        Page<RequestLogStatVo> resultPage = new Page<>(page, limit);
        resultPage.setRecords(stats.subList(start, end));
        resultPage.setTotal(stats.size());
        
        return resultPage;
    }
}